<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="color" padding:center>Click me</button>

    <style>
    #color {
        transition-property: background-color;
        transition-duration: 3s;
    }
    </style>

    <script>
        var count = 0;
    color.onclick = function() {
        if(count == 0){
            this.style.backgroundColor = 'red';
            count = 1;
        }
        else if(count == 1){
            this.style.backgroundColor = 'green';
            count = 0;
        }
    };
    </script>
</body>
</html>